package dao_mysqls

import (
	"family-doctor/common/models"
	"github.com/cheng1005/XxCh-Common/common/global"
	"time"
)

// SendOrderPrompt 发生订单过期提示
func SendOrderPrompt() []models.Orders {
	// 1. 获取所有未支付的订单
	var orders []models.Orders

	nowTime := time.Now().Add(23 * time.Hour).Add(time.Minute * 30)
	global.DB.Where("created_at > ?", nowTime).Find(&orders)

	return orders
}

// OrderExit 订单24h自动取消
func OrderExit() []models.Orders {
	// 1. 获取所有未支付的订单
	var orders []models.Orders
	nowTime := time.Now().Add(24 * time.Hour)
	global.DB.Where("created_at > ?", nowTime).Find(&orders)

	for _, v := range orders {
		global.DB.Delete(models.Orders{Id: v.Id})
	}
	return orders
}
